<template>
  <div>
    <el-form
      :model="ruleForm"
      :rules="rules"
      ref="ruleForm"
      class="login-container"
      label-position="left"
      label-width="0px"
      v-loading="loading"
    >
      <h3 class="login_title">密码重置</h3>
      <el-form-item prop="username">
        <el-input
          type="text"
          auto-complete="off"
          placeholder="登录名"
          v-model="ruleForm.username"
          style="width:220px"
        ></el-input>
      </el-form-item>

      <el-form-item prop="checkEmail">
        <el-input
          type="password"
          auto-complete="off"
          placeholder="邮箱地址"
          v-model="ruleForm.emali"
          style="width:220px"
        ></el-input>
      </el-form-item>
      <!-- <el-form-item prop="oldpassword">
        <el-input
          type="password"
          auto-complete="off"
          placeholder="原密码"
          v-model="ruleForm.oldpassword"
          style="width:220px"
        ></el-input>
      </el-form-item>

      <el-form-item prop="newpassword">
        <el-input
          type="password"
          auto-complete="off"
          placeholder="现密码"
          v-model="ruleForm.nowpassword"
          style="width:220px"
        ></el-input>
      </el-form-item>

      <el-form-item prop="checkPass">
        <el-input
          type="password"
          auto-complete="off"
          placeholder="重复在输入一次"
          v-model="ruleForm.password"
          style="width:220px"
        ></el-input>
      </el-form-item>-->

      <el-button type="primary" style="width: 30%" @click="outTwicePassword()">取消</el-button>
      <el-button type="primary" style="width: 30%" @click="getEmailRandom()">获取验证码</el-button>
      <!-- <el-button type="primary" style="width: 30%" @click="setTwicePassword()">重置密码</el-button> -->
    </el-form>
  </div>
</template>

<script>
export default {
  data() {
    var validatePass2 = (rule, value, callback) => {
      if (this.checkPass === "") {
        callback(new Error("请再次输入密码"));
      } else if (this.checkPass !== this.userForm.password) {
        callback(new Error("两次输入密码不一致!"));
      } else {
        callback();
      }
    };

    var checkEmail = (rule, value, callback) => {
      if (!value) {
        return callback(new Error("邮箱不能为空"));
      } else {
        const reg = /^([a-zA-Z0-9]+[_|\_|\.]?)*[a-zA-Z0-9]+@([a-zA-Z0-9]+[_|\_|\.]?)*[a-zA-Z0-9]+\.[a-zA-Z]{2,3}$/;
        console.log(reg.test(value));
        if (reg.test(value)) {
          callback();
        } else {
          return callback(new Error("请输入正确的邮箱地址"));
        }
      }
    };

    return {
      loading: false,
      checked: false,

      ruleForm: {
        username: "",
        password: "",
        code: "",
        email: ""
      },
      rules: {
        username: [
          { required: true, message: "请输入名称", trigger: "blur" },
          { min: 3, max: 10, message: "长度在 3 到 10 个字符", trigger: "blur" }
        ],
        oldpassword: [
          { required: true, message: "请输入密码", trigger: "blur" },
          { min: 3, max: 10, message: "长度在 3 到 10 个字符", trigger: "blur" }
        ],
        newpassword: [
          { required: true, message: "请输入密码", trigger: "blur" },
          { min: 3, max: 10, message: "长度在 3 到 10 个字符", trigger: "blur" }
        ],
        checkPass: [
          { required: true, validator: validatePass2, trigger: "blur" }
        ],
        checkEmail: [{ required: true, validator: checkEmail, trigger: "blur" }]
      }
    };
  },
  methods: {
    getEmailRandom: function() {
      var hao = this;
      hao.userForm.email;

      var url = "";
      $.ajax({
        url: url,
        method: "get"
      }).then({
        function(obj) {
          if (obj.code) {
          } else {
          }
        }
      });
    }
  }
};
</script>

<style>
.login-container {
  border-radius: 15px;
  background-clip: padding-box;
  margin: 180px auto;
  width: 550px;
  padding: 35px 35px 15px 35px;
  background: #fff;
  background: url("./assets/zsh.jpg");
  border: 1px solid #eaeaea;
  box-shadow: 0 0 25px #cac6c6;
  opacity: 8;
}
.login_title {
  margin: 0px auto 40px auto;
  text-align: center;
  color: #505458;
  opacity: 8;
}
.login_remember {
  margin: 0px 0px 35px 0px;
  text-align: center;
  opacity: 8;
}
</style>



